;----------------------
; OMAURA OLED Installer 
;             20071218
; nicolas@kai-fung.com
;
; modified 20080907
; mvdmuyz@gmail.com
;----------------------

; TODO
; - help pageslicense

;
; - Testing:
;

!include "MUI.nsh"

;-- Colors definition
!define MUI_INSTALLCOLORS "0xFFFFFF 0xFFFFF" ;Two colors
!define MUI_BGCOLOR "FFFFFF" ;header / welcome / finish color
!define MUI_LICENCEPAGE_BGCOLOR "FFFFFF"
!define MUI_DIRECTORYPAGE_BGCOLOR "FFFFFF"
;!define MUI_PAGE_CUSTOMFUNCTION_SHOW SetWhite

;-- Images definition
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP ".\Installer skin\Omaura-Top.bmp" ; 150x57
!define MUI_HEADERIMAGE_UNBITMAP ".\Installer skin\Omaura-Top.bmp" ; 150x57
!define MUI_WELCOMEFINISHPAGE_BITMAP ".\Installer skin\Omaura-Left.bmp" ; 164x314
!define MUI_ABORTWARNING

;-- Icons
!define MUI_ICON ".\Installer skin\omaura.ico"
!define MUI_UNICON ".\Installer skin\omaura.ico"

;-- Pages
!define MUI_WELCOMEPAGE_TITLE_3LINES
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE ".\License.rtf"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES

!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

; Language files
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "French"
!insertmacro MUI_LANGUAGE "German"
!insertmacro MUI_LANGUAGE "Spanish"

!insertmacro MUI_RESERVEFILE_LANGDLL

;---------------------------
;-- Installer Version number
!define VERSION "1.5.1.1"
!define /date NOW "[%Y%m%d]"

;--------------
;-- Declaration
Name "Omaura OLED Software"
Outfile "OmauraOLEDInstall.exe"
BrandingText "omaura installer 2008"
InstallDir "$PROGRAMFILES\omaura\omaura oled"

;----------------------
;-- Vista compatibility
RequestExecutionLevel highest

;--------------------------------
;-- Version Information
  VIProductVersion ${VERSION}
  VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "Omaura OLED Installer"
  VIAddVersionKey /LANG=${LANG_ENGLISH} "CompanyName" "Omaura"
  VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalTrademarks" "(R) Omaura"
  VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "(c) Omaura - 2008"
  VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "Omaura OLED Installer"
  VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" ${VERSION}
  VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductVersion" ${VERSION}

;--------------------------------
;-- Functions

;-- On init load the language files
; currently English (default), French, German, Spanish, Simplified Chinese
Function .onInit
	;Language selection dialog
	Push ""
	Push ${LANG_ENGLISH}
	Push English
	Push ${LANG_FRENCH}
	Push French
	Push ${LANG_GERMAN}
	Push German
	Push ${LANG_SPANISH}
	Push Spanish
	Push A ; A means auto count languages
	       ; for the auto count to work the first empty push (Push "") must remain
	LangDLL::LangDialog "omaura oled installer" "Please select the language of the installer"

	Pop $LANGUAGE
	StrCmp $LANGUAGE "cancel" 0 +2
		Abort
FunctionEnd

;--------------
; Install Parts
Section "Install"

  ;-------------
  ;-- Files Copy
  ; Set output path to the installation directory.
  SetOutPath $INSTDIR
  
  ; Put file there
  File "..\bin\Release\*.*"
 
	; Files Transfer
	;- create directories
	CreateDirectory $INSTDIR\Resources
  	CreateDirectory $INSTDIR\Resources\Icons
	CreateDirectory $INSTDIR\Resources\Lang
	CreateDirectory $INSTDIR\Resources\Logo
	CreateDirectory $INSTDIR\Resources\Logo\Bye
	CreateDirectory $INSTDIR\Resources\Logo\Welcome
	CreateDirectory $INSTDIR\Resources\Help
	CreateDirectory $INSTDIR\Resources\Help\resources
	CreateDirectory $INSTDIR\Resources\Driver
	CreateDirectory $INSTDIR\Resources\Driver\Vista
	CreateDirectory $INSTDIR\Resources\Themes
	CreateDirectory $INSTDIR\Resources\Weather
	;CreateDirectory $INSTDIR\Resources\Themes\Current
	CreateDirectory $INSTDIR\Resources\Themes\Omaura(3D)
	CreateDirectory $INSTDIR\Resources\Themes\Omaura(3D)\Img
	CreateDirectory $INSTDIR\Resources\Themes\Omaura(default)
	CreateDirectory $INSTDIR\Resources\Themes\Omaura(default)\Img
	CreateDirectory $INSTDIR\Resources\Themes\Omaura(round)		
	CreateDirectory $INSTDIR\Resources\Themes\Omaura(round)\Img
    
    ;- copy files
	SetOutPath $INSTDIR\Resources\Icons
	File /x *.bak "..\Resources\Icons\*.*"
	
	SetOutPath $INSTDIR\Resources\Lang
	File /x *.bak "..\Resources\Lang\*.*"
	
	SetOutPath $INSTDIR\Resources\Logo\Bye
	File /x *.bak "..\Resources\Logo\Bye\*.*"
	
	SetOutPath $INSTDIR\Resources\Logo\Welcome
	File /x *.bak "..\Resources\Logo\Welcome\*.*"
	
	SetOutPath $INSTDIR\Resources\Help
	File /x *.bak "..\Resources\Help\*.*"
	
	SetOutPath $INSTDIR\Resources\Help\resources
	File /x *.bak "..\Resources\Help\resources\*.*"

	SetOutPath $INSTDIR\Resources\Driver\Vista
	File /x *.bak "..\Resources\Driver\Vista\*.*"
	
	SetOutPath $INSTDIR\Resources\Themes
	File /x *.bak "..\Resources\Themes\*.*"
	
	SetOutPath $INSTDIR\Resources\Weather
	File /x *.bak "..\Resources\Weather\*.*"

	;SetOutPath $INSTDIR\Resources\Themes\Current
	;File /x *.bak "..\Resources\Themes\Current\*.*"
	
	SetOutPath $INSTDIR\Resources\Themes\Omaura(3D)
	File /x *.bak "..\Resources\Themes\Omaura(3D)\*.*"

	SetOutPath $INSTDIR\Resources\Themes\Omaura(3D)\Img
	File /x *.bak "..\Resources\Themes\Omaura(3D)\Img\*.*"
		
	SetOutPath $INSTDIR\Resources\Themes\Omaura(default)
	File /x *.bak "..\Resources\Themes\Omaura(default)\*.*"

	SetOutPath $INSTDIR\Resources\Themes\Omaura(default)\Img
	File /x *.bak "..\Resources\Themes\Omaura(default)\Img\*.*"

  ;---------------------------------------------------------
  ; create users/<current>/AppData/omaura/omaura oled folder
  ;        this place is used for
  ;             - the config.ini (read/write)
  ;             - log
  
  ; create directories
  CreateDirectory "$LOCALAPPDATA\omaura"
  CreateDirectory "$LOCALAPPDATA\omaura\omaura oled"
  
  ; create install.txt
  ClearErrors
  FileOpen $0 "$LOCALAPPDATA\omaura\omaura oled\install.txt" w
  IfErrors done
  FileWrite $0 $INSTDIR 
  FileClose $0
  done:

  
  ; copy files
  SetOutPath "$LOCALAPPDATA\omaura\omaura oled"
             File  /x *.bak "..\Resources\AppData\*.*"
             
  ;--------------------
  ;-- Reg MSASState.dll
  WriteRegStr HKCR "MSASState.MediaStatusSink" "" "MSASState.MediaStatusSink"
  WriteRegStr HKCR "MSASState.MediaStatusSink\CLSID" "" "{380AA9F1-5047-40D0-8BE9-18AB489CA469}"
  
  WriteRegStr HKCR "CLSID\{380AA9F1-5047-40D0-8BE9-18AB489CA469}" "" "MSASState.MediaStatusSink"
  
  WriteRegStr HKCR "CLSID\{380AA9F1-5047-40D0-8BE9-18AB489CA469}\InprocServer32" "" "mscoree.dll"
  WriteRegStr HKCR "CLSID\{380AA9F1-5047-40D0-8BE9-18AB489CA469}\InprocServer32" "ThreadingModel" "Both"
  WriteRegStr HKCR "CLSID\{380AA9F1-5047-40D0-8BE9-18AB489CA469}\InprocServer32" "Class" "MSASState.MediaStatusSink"
  WriteRegStr HKCR "CLSID\{380AA9F1-5047-40D0-8BE9-18AB489CA469}\InprocServer32" "Assembly" "MSASState, Version=6.0.6000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
  WriteRegStr HKCR "CLSID\{380AA9F1-5047-40D0-8BE9-18AB489CA469}\InprocServer32" "RuntimeVersion" "v2.0.50727"
  WriteRegStr HKCR "CLSID\{380AA9F1-5047-40D0-8BE9-18AB489CA469}\InprocServer32" "CodeBase" "file:///$INSTDIR/MSASState.DLL"
  
  WriteRegStr HKCR "CLSID\{380AA9F1-5047-40D0-8BE9-18AB489CA469}\ProgId" "" "MSASState.MediaStatusSink"
  
  WriteRegStr HKCR "CLSID\{380AA9F1-5047-40D0-8BE9-18AB489CA469}\Implemented Categories\{62C8FE65-4EBB-45E7-B440-6E39B2CDBF29}" "" ""
  WriteRegStr HKCR "CLSID\{380AA9F1-5047-40D0-8BE9-18AB489CA469}\Implemented Categories\{FCB0C2A3-9747-4c95-9d02-820AFEDEF13F}" "" "Media Status Sink"
  
  ;----------------------------------
  ;-- Reg the installer / uninstaller
  
  ;-- Write the uninstall keys for Windows
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OLED" "DisplayName" "OLED Software"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OLED" "UninstallString" '"$INSTDIR\uninstall.exe"'
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OLED" "NoModify" 1
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OLED" "NoRepair" 1
  WriteUninstaller "uninstall.exe"
  
  ;--------------------
  ;-- Add to Start Menu
  SetOutPath $INSTDIR ;Important line if not setup to the exe position, it's not working .................
  CreateShortCut "$SMSTARTUP\OLED.lnk" "$INSTDIR\omaura oled.exe" "" "$INSTDIR\Resources\Icons\omaura.ico"
  
  ;---------------------
  ;-- Create Menu Folder
  CreateDirectory "$SMPROGRAMS\omaura"
  CreateDirectory "$SMPROGRAMS\omaura\omaura oled"
  ;-- Link Definition
  CreateShortCut "$SMPROGRAMS\omaura\omaura oled\OLED.lnk" "$INSTDIR\omaura oled.exe" "" "$INSTDIR\Resources\Icons\omaura.ico"
  CreateShortCut "$SMPROGRAMS\omaura\omaura oled\uninstall.lnk" "$INSTDIR\uninstall.exe"
  
  MessageBox MB_YESNO|MB_ICONQUESTION "The omaura software will be definitivly installed after rebooting. Do you want to reboot now" IDNO +2
        Reboot
  
  
SectionEnd

;--------------
;-- Uninstaller

Section "Uninstall"

  ;-- Remove shortcuts, if any
  ;--- change the shellvarcontext
  SetShellVarContext current

  IfFileExists "$SMPROGRAMS\omaura\omaura oled\Oled.lnk" 0 +2
        Delete "$SMPROGRAMS\omaura\omaura oled\Oled.lnk"
  IfFileExists "$SMPROGRAMS\omaura\omaura oled\uninstall.lnk" 0 +2
        Delete "$SMPROGRAMS\omaura\omaura oled\uninstall.lnk"
  IfFileExists $SMSTARTUP\OLED.lnk 0 +2
        Delete $SMSTARTUP\OLED.lnk
  
  ;-- Remove AppData files
  Delete "$LOCALAPPDATA\omaura\omaura oled\*.*"
  
  ;-- Remove AppData folder
  RMDir "$LOCALAPPDATA\omaura\omaura oled"
  
  ;-- Remove registry keys
  DeleteRegKey HKCR "CLSID\{380AA9F1-5047-40D0-8BE9-18AB489CA469}"
  DeleteRegKey HKCR "MSASState.MediaStatusSink"
  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OLED"
  
  ;-- Remove files and uninstaller
  Delete $INSTDIR\Resources\Icons\*.*
  Delete $INSTDIR\Resources\Lang\*.*
  Delete $INSTDIR\Resources\Logo\Bye\*.*
  Delete $INSTDIR\Resources\Logo\Welcome\*.*
  Delete $INSTDIR\Resources\Help\*.*
  Delete $INSTDIR\Resources\Help\resources\*.*
  Delete $INSTDIR\Resources\Driver\Vista\*.*
  Delete $INSTDIR\Resources\Themes\*.*
  Delete $INSTDIR\Resources\Weather\*.*
  ;Delete $INSTDIR\Resources\Themes\Current\*.*
  Delete $INSTDIR\Resources\Themes\Omaura(3D)\*.*
  Delete $INSTDIR\Resources\Themes\Omaura(3D)\Img\*.*
  Delete $INSTDIR\Resources\Themes\Omaura(default)\*.*
  Delete $INSTDIR\Resources\Themes\Omaura(default)\Img\*.*
  Delete $INSTDIR\Resources\Themes\Omaura(round)\*.*
  Delete $INSTDIR\Resources\Themes\Omaura(round)\Img\*.*  
  Delete $INSTDIR\*.*

  ;-- Remove directories used
  RMDir "$SMPROGRAMS\omaura\omaura oled"
  RMDir "$SMPROGRAMS\omaura"
  
  RMDir "$INSTDIR\Resources\Icons"

  RMDir "$INSTDIR\Resources\Lang"

  RMDir "$INSTDIR\Resources\Logo\Welcome"
  RMDir "$INSTDIR\Resources\Logo\Bye"
  RMDir "$INSTDIR\Resources\Logo"

  RMDir "$INSTDIR\Resources\Help\resources"
  RMDir "$INSTDIR\Resources\Help"

  RMDir "$INSTDIR\Resources\Driver\Vista"
  RMDir "$INSTDIR\Resources\Driver"

  RMDir "$INSTDIR\Resources\Weather"

  ;RMDir "$INSTDIR\Resources\Themes\Current"
  RMDir "$INSTDIR\Resources\Themes\Omaura(3D)\Img"
  RMDir "$INSTDIR\Resources\Themes\Omaura(3D)"
  RMDir "$INSTDIR\Resources\Themes\Omaura(default)\Img"
  RMDir "$INSTDIR\Resources\Themes\Omaura(default)"
  RMDir "$INSTDIR\Resources\Themes\Omaura(round)\Img"
  RMDir "$INSTDIR\Resources\Themes\Omaura(round)"
  RMDir "$INSTDIR\Resources\Themes"

  RMDir "$INSTDIR\Resources"

  RMDir "$INSTDIR"
  
SectionEnd